// Shared
PrecacheParticleSystem("aura_dark")
PrecacheParticleSystem("aura_flames")
PrecacheParticleSystem("aura_toxic")
PrecacheParticleSystem("aura_antimatter")
PrecacheParticleSystem("aura_frost")
PrecacheParticleSystem("aura_light")

HG = {}

HG.PLAYERDUMMIES = {}

HG.Servers = {
	[1] = {name="Serious RP",		ip="75.126.83.192:27015",	gif_url="http://cache.www.gametracker.com/server_info/75.126.83.192:27015/b_350_20_691108_170403_FFFFFF_915050.png",online=false},
	[2] = {name="PERP 3.0",			ip="75.126.83.210:27015",	gif_url="http://cache.www.gametracker.com/server_info/75.126.83.210:27015/b_350_20_5BE949_476666_0B2137_000000.png",online=false},
	[3] = {name="Zombie Suvival",	ip="75.126.83.209:27015",	gif_url="http://cache.www.gametracker.com/server_info/75.126.83.209:27015/b_350_20_000000_105F0C_3351FF_03DB00.png",online=false},
	[4] = {name="Stronghold",		ip="75.126.83.213:27015",	gif_url="http://cache.www.gametracker.com/server_info/75.126.83.213:27015/b_350_20_636363_000000_C3BD37_FF870A.png",online=false},
	[5] = {name="TTT",				ip="75.126.83.194:27015",	gif_url="http://cache.www.gametracker.com/server_info/75.126.83.194:27015/b_350_20_692108_381007_FFFFFF_000000.png",online=false},
}

HG.ITEMS = {}

HG.MODELS = {}

HG.EDITOR = {
	_DIR = "HGF/itemdata/editor/",
	["items_nid"] = {
		offset={pos=Vector(0,0,0),ang=Angle(0,0,0),scale=Vector(1,1,1)},
		pricing={current=0,modifier=0,multiplier=0.00,random_min=0,random_max=1}
	}
}

HG.MARKET = {
	_DIR = "HGF/itemdata/global_market.txt",
	["item_nid"] = {
		purchased=0,
		sold=0,
		price=0,
		feedback={good=0,bad=0,avg=0},
		rarity = 0
	}
}

SLOT_HAT 	= 1
SLOT_TRAIL 	= 2
SLOT_AURA 	= 3

HG.SLOTS = {
	[SLOT_HAT] = {name="Hat",bone="ValveBiped.Bip01_Head1",attch=""},
	[SLOT_TRAIL] = {name="Trail",bone="ValveBiped.Bip01_Spine3",attch=""},
	[SLOT_AURA] = {name="Aura",bone="",attch=""}
}

/*-------------------------------------------------
	Item functions
-------------------------------------------------*/

// Taken from an my old gamemode
function HG.LoadItems()
	for k, filename in ipairs( file.FindInLua( "hgcore/items/*.lua" ) ) do
		ITEM = { } //Define the item table, so the other items are not just errors loading...
		
		if ( SERVER ) then 
			AddCSLuaFile( "hgcore/items/"..filename ); //Add this to the client, so we don't need more usermessages
		end 
		include( "hgcore/items/"..filename ); //Include both server and client
		
		if !( ITEM.UniqueID ) then //If the item has a class
			filename = string.gsub(filename,".lua","")
			ErrorNoHalt(  "Item :"..tostring( filename ) .. " has no UniqueID\n") //Error and continue on it's way
			ITEM.UniqueID = filename
		end
		
		ITEM.ID = k
		HG.ITEMS[ITEM.UniqueID] = ITEM
		print( "\tLoaded and registered item: ["..tostring(filename).."] "..tostring(ITEM.PrintName) )
	end
end

HG.LoadItems()

function HG.OrganizedItems()
	local ITEMS = {} 
	for k, v in pairs(table.Copy(HG.ITEMS)) do 
		ITEMS[v.ID]=k 
	end 
	return ITEMS
end

function HG.Item(itemid) return HG.ITEMS[itemid] end
function HG.ItemIsValid(itemid) return tobool(HG.Item(itemid)) end

function HG.ItemSlot(itemid) return HG.Item(itemid).Slot end
function HG.ItemName(itemid) return HG.Item(itemid).PrintName end
function HG.ItemBPrice(itemid) return HG.Item(itemid).BuyPrice end
function HG.ItemSPrice(itemid) return HG.Item(itemid).SellPrice end
function HG.ItemDesc(itemid) return HG.Item(itemid).Description end
function HG.ItemID(itemid) return HG.Item(itemid).ID end
function HG.UniqueIDFromID(id)
	for k, itemid in pairs( HG.OrganizedItems() ) do
		if k == id then
			print( "\t\t UniqueID found for ID#"..id.." == "..itemid )
			return itemid
		end
	end
end

function _R.Player:hg_CreateEquipmentDummy()
	if self._Dummy then 
		self:hg_RemoveEquipmentDummy() 
	else
		self._Dummy = nil
		if SERVER then
			self._Dummy = ents.Create( "prop_ragdoll" )
			self._Dummy:SetModel(self:GetModel())
		else
			self._Dummy = ClientsideModel(self:GetModel(),RENDERGROUP_OPAQUE)
		end
		self._Dummy:SetParent(self)
		self._Dummy:SetColor(0,0,0,0)
		self._Dummy:AddEffects(EF_BONEMERGE)
		self._Dummy:Spawn()
		self._Dummy.Owner = self
		HG.PLAYERDUMMIES[self] = self._Dummy
	end
end

function _R.Player:hg_RemoveEquipmentDummy()
	HG.PLAYERDUMMIES[self] = nil
	SafeRemoveEntity(self._Dummy)
	self._Dummy = nil
end